/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/11/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfexamine.struts.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.yfexamine.commons.Constants;
import com.application.yfexamine.entity.YfExmaine;
import com.application.yfexamine.service.YfExmaineService;
import com.application.yfexamine.struts.form.YfExmaineForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
 /**
 * 
 * Description:YfExmaineAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 02/11/2012 
 * 
 */
public class YfExmaineAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfExmaineService yfExmaineService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfExmaine yfExmaine;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfExmainePartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfExmaine" + "开始");
		YfExmaineForm yfExmaine = (YfExmaineForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfExmaineList = null;
		resultSize = yfExmaineService.getAllCountYfExmaine(yfExmaine);
		pageBean = PageBean.getPageBean("yfExmaineTab", resultSize,request);
		yfExmaineList = yfExmaineService.searchYfExmaine(yfExmaine,pageBean);
		request.setAttribute("yfExmaineList", yfExmaineList);

		log.debug("searchYfExmaine" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfExmaine(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfExmaines");
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfExmaine(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfExmaines");
		YfExmaine yfExmaine = this.getYfExmaine(form);
                yfExmaine.setId(RandomKey.generateID_Long_19());
		 yfExmaine.setExaminePerson(CommonUtil.getCurrentUser(request).getId().toString());
		 yfExmaine.setExamineDate(new Date());

		this.yfExmaineService.insertObject(yfExmaine);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfExmaine(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfExmaines");
		YfExmaineForm yfExmaineForm = (YfExmaineForm) form;
		this.yfExmaineService.deleteYfExmaines(yfExmaineForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfExmaine(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfExmaines");

		YfExmaine yfExmaine = this.getYfExmaine(form);
		yfExmaine = this.yfExmaineService.getYfExmaine(yfExmaine);
		request.setAttribute(Constants.YFEXMAINE, yfExmaine);
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfExmaine(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfExmaines");
		YfExmaine yfExmaine = this.getYfExmaine(form);
		 yfExmaine.setExaminePerson(CommonUtil.getCurrentUser(request).getId().toString());
		 yfExmaine.setExamineDate(new Date());
		this.yfExmaineService.updateObject(yfExmaine);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfExmaine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfExmaine");

		YfExmaine yfExmaine = this.getYfExmaine(form);
		yfExmaine = this.yfExmaineService.getYfExmaine(yfExmaine);
		request.setAttribute(Constants.YFEXMAINE, yfExmaine);
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfExmaineService
	 */
	public YfExmaineService getYfExmaineService() {
		return this.yfExmaineService;
	}

	/**
	 * @param YfExmaineService
	 *  the YfExmaineService to set
	 */
	public void setYfExmaineService(YfExmaineService yfExmaineService) {
		this.yfExmaineService = yfExmaineService;
	}

	/**
	 * 获取YfExmaine实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfExmaine
	 */
	public YfExmaine getYfExmaine(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfExmaineForm yfExmaineForm = (YfExmaineForm) form;
		yfExmaine = new YfExmaine();
		BeanUtils.copyProperties(yfExmaine, yfExmaineForm);
		return yfExmaine;
	}
    
        public void setYfExmaine(YfExmaine yfExmaine) {
		this.yfExmaine = yfExmaine;
	}

}
